<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
      <table class="layui-table">
        <thead>
          <tr>
            <th>订单详情编号</th>
            <th>商品名称</th>
            <th>商品图片</th>
            <th>商品个数</th>
            <th>商品价格</th>
            <th >操作</th>
            </tr>
        </thead>
        <tbody>
          <c:forEach items="${orderDetail}" var="order">
            <tr id="tr_${order.odid}">
              <td>${order.odid}</td>
              <td>${order.goods.goodsName}</td>
              <td><img src="${order.goods.goodsImage}"></td>
              <td>${order.odnumber}</td>
                <input name="oldprice" value="${order.odprice}" type="hidden" />
              <td><input name="odprice" type="number" value="${order.odprice}" readonly />${order.odprice}</td>
              <td class="td-manage">
                <c:if test="${fn:contains(auths,'updOrderDetail')}">
                  <button onclick="b('${order.odid}','${order.odnumber}','${order.oid}')" >编辑</button>
                  <button style="display: none" onclick="c('${order.odid}')">取消</button>
                </c:if>
              </td>
            </tr>
          </c:forEach>
        </tbody>
      </table>
    </div>
    <script>
        function b(id,num,oid){
            if($("#tr_"+id+" input[name='odprice']").prop("readonly")){
                $("#tr_"+id+" input[name='odprice']").removeAttr("readonly")
                $("#tr_"+id+" button").eq(0).text("确定")
                $("#tr_"+id+" button").eq(1).attr("style","")
            }else{
                $("#tr_"+id+" input[name='odprice']").attr("readonly","readonly")
                $("#tr_"+id+" button").eq(0).text("编辑")
                $("#tr_"+id+" button").eq(1).attr("style","display:none;")
                $.ajax({
                    url:"updOrderDetail",
                    type:"post",
                    data:{"oid":oid,"odnumber":num,"odid":id,"odprice":$("#tr_"+id+" input[name='odprice']").val(),"oldprice":$("#tr_"+id+" input[name='oldprice']").val()},
                    success:function (res) {
                        if(res.result=="0000"){
                            alert("修改成功")
                            $("#tr_"+id+" input[name='oldprice']").val($("#tr_"+id+" input[name='odprice']").val())
                        }else{
                            alert("修改失败")
                        }
                    },
                    dataType:"json"
                })
            }
        }
        function c(id){
            $("#tr_"+id+" input[name='odprice']").attr("readonly","readonly")
            $("#tr_"+id+" button").eq(0).text("编辑")
            $("#tr_"+id+" button").eq(1).attr("style","display:none;")
        }
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });
    </script>
  </body>

</html>